<!--正则表达式学习实践-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="#" method="post" id="FromTest">
    <div id="err" style="color: red"></div>
    <div> 姓名:<input id="name" name="name"></div>
    <div> 身份证:<input id="idno" name="idno"></div>
    <div><input type="submit"></div>
</form>
<script>
    document.getElementById("FromTest").onsubmit = function () {
        const name1 = /^[\u4e00-\u9fa5]{2,10}$/;
        const idno1 = /^[1234568]\d{16}[0-9xX]$/;
        let name = document.getElementById("name").value;
        let idno = document.getElementById("idno").value;
        if (!name1.test(name)) {
            document.getElementById("err").innerHTML = "无效姓名";
            return false;
        } else if (!idno1.test(idno)) {
            document.getElementById("err").innerHTML = "无效身份证";
            return false;
        } else {
            alert("验证通过");
            return true;
        }
    };
</script>
</body>
</html>